package com.hisan.waimaidao.carvas;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Toast;

public class MyView extends View {
    
    //默认调用此方法
    public MyView(Context context) {
        super(context);
        init(context);
    }
    //引用布局后调用此方法
    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void init(Context context) {


    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            int size=MeasureSpec.getSize(widthMeasureSpec);
            int mode=MeasureSpec.getMode(widthMeasureSpec);
            //EXACTLY:精准模式  UNSPECIFIE:普通模式
            if (mode==MeasureSpec.EXACTLY){
                Toast.makeText(getContext(),size+"",Toast.LENGTH_LONG).show();
            }
        setMeasuredDimension(200,200);
    }

}
